package com.yanxibao.controller;

import com.yanxibao.bean.Um;
import com.yanxibao.common.Result;
import com.yanxibao.dto.PageQueryDTO;
import com.yanxibao.service.UmService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;


/**
 * 院校专业;(_um)表控制层
 *
 * @author kongke
 * @date 2023/11/16
 */
@Slf4j
@Api(tags = "院校专业对象功能接口")
@RestController
@CrossOrigin
@RequestMapping("/Um")
public class UmController {

    @Resource
    private UmService umService;


    /**
     * 通过ID查询单条数据
     *
     * @param umId 主键
     */
    @ApiOperation("通过ID查询单条数据")
    @GetMapping("/getById/{umId}")
    @ResponseBody
    public Result<Um> queryById(@PathVariable("umId") Integer umId) {
        return umService.queryById(umId);
    }


    /**
     * 查询全部
     */
    @ApiOperation("查询全部数据")
    @GetMapping("/all")
    public Result<List<Um>> queryAll(@RequestBody Um um) {
        return umService.queryAll(um);
    }

    /**
     * 分页查询
     */
    @ApiOperation("分页查询")
    @PostMapping("/getPage")
    @ResponseBody
    public Result<PageQueryDTO<Um>> pageQuery(@RequestParam("current") Integer current,
                                              @RequestParam("size") Integer size,
                                              @RequestBody Um um) {

        return umService.pageQuery(um, current, size);
    }


    /**
     * 新增数据
     *
     * @param um 实例对象
     */
    @ApiOperation("新增数据")
    @PostMapping("/add")
    public Result<Um> add(@RequestBody Um um) {
        return umService.insert(um);
    }

    /**
     * 更新数据
     *
     * @param um 实例对象
     */
    @ApiOperation("更新数据")
    @PutMapping("/update")
    public Result<Um> edit(@RequestBody Um um) {
        return umService.update(um);
    }

    /**
     * 通过主键删除数据
     *
     * @param id 主键
     */
    @ApiOperation("通过主键删除数据")
    @DeleteMapping("/del/{id}")
    public Result<Boolean> deleteById(@PathVariable Integer id) {
        return umService.deleteById(id);
    }
}